package com.txts.road.admin.eventSys.controller;

import com.txts.base.common.domain.PageResult;
import com.txts.base.common.domain.ResponseDTO;
import com.txts.road.admin.common.annotation.Anonymous;
import com.txts.road.admin.common.annotation.Log;
import com.txts.road.admin.common.core.controller.BaseController;
import com.txts.road.admin.common.core.domain.AjaxResult;
import com.txts.road.admin.common.core.page.TableDataInfo;
import com.txts.road.admin.common.enums.BusinessType;
import com.txts.road.admin.common.utils.poi.ExcelUtil;
import com.txts.road.admin.eventSys.domain.EventInfo;
import com.txts.road.admin.eventSys.service.IEventInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * 赛事信息Controller
 *
 * @author ruoyi
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/eventSys/eventInfo")
@Tag(name = "赛事活动接口")
public class EventInfoController extends BaseController {
    @Resource
    private IEventInfoService eventInfoService;

    /**
     * 查询赛事信息列表
     */
    @Anonymous
    @GetMapping("/list")
    @Operation(summary = "查询赛事信息列表", description = "根据条件查询赛事信息列表")
    public ResponseDTO<PageResult<EventInfo>> list(EventInfo eventInfo) {
        startPage();
        List<EventInfo> list = eventInfoService.selectEventInfoList(eventInfo);
        return getDataTable(list);
    }

    /**
     * 导出赛事信息列表
     */
    @PreAuthorize("@ss.hasPermi('eventSys:eventInfo:export')")
    @Log(title = "赛事信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出赛事信息列表", description = "导出赛事信息列表")
    public void export(HttpServletResponse response, EventInfo eventInfo) {
        List<EventInfo> list = eventInfoService.selectEventInfoList(eventInfo);
        ExcelUtil<EventInfo> util = new ExcelUtil<EventInfo>(EventInfo.class);
        util.exportExcel(response, list, "赛事信息数据");
    }

    /**
     * 获取赛事信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('eventSys:eventInfo:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取赛事信息详细信息", description = "根据ID获取赛事信息详细信息")
     public ResponseDTO<Object> getInfo(@PathVariable("id") Long id) {
        return success(eventInfoService.selectEventInfoById(id));
    }

    /**
     * 新增赛事信息
     */
    @PreAuthorize("@ss.hasPermi('eventSys:eventInfo:add')")
    @Log(title = "赛事信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增赛事信息", description = "新增赛事信息")
    public ResponseDTO<Object>add(@RequestBody EventInfo eventInfo) {
        return toAjax(eventInfoService.insertEventInfo(eventInfo));
    }

    /**
     * 修改赛事信息
     */
    @PreAuthorize("@ss.hasPermi('eventSys:eventInfo:edit')")
    @Log(title = "赛事信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改赛事信息", description = "修改赛事信息")
    public ResponseDTO<Object>edit(@RequestBody EventInfo eventInfo) {
        return toAjax(eventInfoService.updateEventInfo(eventInfo));
    }

    /**
     * 删除赛事信息
     */
    @PreAuthorize("@ss.hasPermi('eventSys:eventInfo:remove')")
    @Log(title = "赛事信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除赛事信息", description = "删除赛事信息")
    public ResponseDTO<Object>remove(@PathVariable Long[] ids) {
        return toAjax(eventInfoService.deleteEventInfoByIds(ids));
    }
}
